<template>
	<view>
		<view class="topImg">废旧金属回收登记系统</view>
		<view class="title">数据记录</view>
		<view class="allList">
			<view class="oneList" v-for="(item,index) in list" :key="index">
				<view class="one">
					客户姓名：{{item.userName}}
				</view>
				<view class="one">
					客户电话：{{item.userPhone}}
				</view>
				<view class="one">
					客户身份证：{{item.userIdCard}}
				</view>
				<view class="one">
					垃圾名称：{{item.threeName}}
				</view>
				<view class="one">
					金属种类：{{item.oneName}}
				</view>
				<view class="one">
					分类：{{item.twoName}}
				</view>
				<view class="one">
					重量：{{item.weight}}kg
				</view>
				<view class="one">
					图片：
				<u-popup v-model="showImg" mode="center">
					<image :src="imgUrl" style="width: 90vw;height: 50vh;" mode="aspectFit"></image>
				</u-popup>
				<image v-if="showPic" @tap="scan(item.picture)" :src="item.picture" style="width: 100rpx;height: 100rpx;margin-right: 10rpx;" mode="aspectFit"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import config from '@/utils/config.js';
	export default {
		data(){
			return {
				list:[],
				showImg:false,
				imgUrl:"",
				route:"",
				showPic:false,
			}
		},
		onShow(){
			this.getList();
			this.getToken();
		},
		onLoad(option){
			this.route = option.route;
		},
		destroyed() {
			if(this.route == "info"){
				uni.navigateTo({
					url:"../index/index"
				})
			}
		},
		methods:{
			scan(url){
				this.showImg = true;
				this.imgUrl = url;
			},
			getToken(){
				uni.request({
					url: config.host + '/huishou/pcLogin/getAppLoginInfo', //接口地址。
					data: {
						token: uni.getStorageSync('token')
					},
					method: 'POST',
					header: {
						'content-type': 'application/json;charset=UTF-8'
					},
					success: (res) => {
						if(Object.keys(res.data.item).length == 0){
							uni.showToast({
								icon: 'none',
								title: '身份已过期，请重新登录！'
							});
							setTimeout(() => {
								uni.navigateTo({
									url: '../login/index'
								})
							}, 800);
							
						}else{
							
						}
					},
					fail: (err) => {
						uni.showToast({
							icon: 'none',
							title: '网络异常,请稍后重试'
						});
					}
				});
			},
			getList(){
				uni.request({
					url: config.host + '/huishou/scrapinformation/queryList ', //接口地址。
					data: {
						"currentPage":1,
						"pageSize":99999999,
						"submitter": uni.getStorageSync('userId')
					},
					method: 'POST',
					header: {
						'content-type': 'application/json;charset=UTF-8'
					},
					success: (res) => {
						console.log(res,"res-------------------")
						if (res.data.code == 200) {
							this.list = res.data.items;
							this.list.forEach((item,i)=>{
								console.log(this.list[i].picture.split(","),"nnnnnnnnnnnnnn")
								if(this.list[i].picture != ""){
									// this.list[i].picture = this.list[i].picture.split(",");
									this.showPic = true;
								}else{
									this.showPic = false;
								}
							})
						} 
					},
					fail: (err) => {
						uni.showToast({
							icon: 'none',
							title: '网络异常,请稍后重试'
						});
					}
				});
			}
		}
	}
</script>

<style lang="scss">
	@import url("./css/index.css");
</style>
